package ExecuteEngine;

import parse.*;
import java.util.*;

import SystemManagement.*;

public class Project implements Operation{
	public Attribute_list attr_list;
	public Operation op;
	public Tuple tuple;
	
	public Project(Attribute_list a, Operation o){
		this.attr_list = a;
		this.op = o;
	}
	
	public void Open(){
		op.Open();
	}
	
	public boolean hasNext(){
		return this.op.hasNext();
	}
	
	public Tuple GetNext()
	{
		Tuple src = op.GetNext();
		tuple = new Tuple();
		
		if(attr_list.attributes.get(0).equals("*"))
			return src;
		
		for(int i=0; i<src.tuple.size(); i++){
			String s = src.tuple.get(i).attrName;
			
			for(int j=0; j<attr_list.attributes.size(); j++){
				if(attr_list.attributes.get(i).GetAttr_Name().equals(s)){
					tuple.addElement(src.tuple.get(i));
					break;
				}
			}
		}
		
		return tuple;
	}
	
	public void Close(){
		op.Close();
	}
}
